Fix bugs related to the virtual TPM. Also make the vTPM
authorkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Thu, 16 Feb 2006 22:00:00 +0000 (23:00 +0100)
committerkaf24@firebug.cl.cam.ac.uk <kaf24@firebug.cl.cam.ac.uk>
Thu, 16 Feb 2006 22:00:00 +0000 (23:00 +0100)
manager listen on /dev/vtpm.

Signed-off-by: Stefan Berger <stefanb@us.ibm.com>
linux-2.6-xen-sparse/drivers/char/tpm/tpm_xen.c
linux-2.6-xen-sparse/drivers/xen/tpmfront/tpmfront.c
tools/vtpm/Makefile
tools/vtpm/tpm_emulator.patch
tools/vtpm_manager/manager/vtpmpriv.h

index a3097fa829292fc490ebd93ee7edabcd233fe127..c3c571c3ff9794d34a1fb8236b404ac546a83f62 100644 (file)
@@ -469,6 +469,9 @@ static int __init init_xen(void)
 {
        int rc;
 
+       if ((xen_start_info->flags & SIF_INITDOMAIN)) {
+               return -EPERM;
+       }
        /*
         * Register device with the low lever front-end
         * driver
index 8d76033eb942eb83a51a23c25b0bc5e8dd9e50d0..1d7b3413830dfff841d0ccde33df494e3cb02209 100644 (file)
@@ -129,17 +129,18 @@ static inline void tpm_private_init(struct tpm_private *tp)
 static struct tpm_private *tpm_private_get(void)
 {
        if (!my_priv) {
-               my_priv = kzalloc(sizeof(struct tpm_private), GFP_KERNEL);
-               if (my_priv) {
-                       tpm_private_init(my_priv);
-               }
-        }
-        return my_priv;
+               my_priv = kzalloc(sizeof(struct tpm_private), GFP_KERNEL);
+               if (my_priv) {
+                       tpm_private_init(my_priv);
+               }
+       }
+       return my_priv;
 }
 
-static inline void tpm_private_free(struct tpm_private *tp)
+static inline void tpm_private_free(void)
 {
-       kfree(tp);
+       kfree(my_priv);
+       my_priv = NULL;
 }
 
 /**************************************************************
@@ -158,7 +159,7 @@ static struct tpmfe_device *upperlayer_tpmfe;
  */
 int tpm_fe_send(struct tpm_private *tp, const u8 * buf, size_t count, void *ptr)
 {
-       int sent = 0;
+       int sent;
 
        down(&suspend_lock);
        sent = tpm_xmit(tp, buf, count, 0, ptr);
@@ -180,6 +181,9 @@ int tpm_fe_register_receiver(struct tpmfe_device *tpmfe_dev)
                upperlayer_tpmfe = tpmfe_dev;
                tpmfe_dev->max_tx_size = TPMIF_TX_RING_SIZE * PAGE_SIZE;
                tpmfe_dev->tpm_private = tpm_private_get();
+               if (!tpmfe_dev->tpm_private) {
+                       rc = -ENOMEM;
+               }
        } else {
                rc = -EBUSY;
        }
@@ -355,10 +359,10 @@ static void backend_changed(struct xenbus_device *dev,
                break;
 
        case XenbusStateClosed:
-               if (tp->is_suspended == 0) {
-                       device_unregister(&dev->dev);
-               }
-               break;
+               if (tp->is_suspended == 0) {
+                       device_unregister(&dev->dev);
+               }
+               break;
        }
 }
 
@@ -380,12 +384,12 @@ static int tpmfront_probe(struct xenbus_device *dev,
                return err;
        }
 
-        tp->dev = dev;
-        dev->data = tp;
+       tp->dev = dev;
+       dev->data = tp;
 
        err = talk_to_backend(dev, tp);
        if (err) {
-                tpm_private_free(tp);
+               tpm_private_free();
                dev->data = NULL;
                return err;
        }
@@ -395,7 +399,7 @@ static int tpmfront_probe(struct xenbus_device *dev,
 
 static int tpmfront_remove(struct xenbus_device *dev)
 {
-        struct tpm_private *tp = dev->data;
+       struct tpm_private *tp = dev->data;
        destroy_tpmring(tp);
        return 0;
 }
@@ -433,7 +437,7 @@ tpmfront_suspend(struct xenbus_device *dev)
 static int
 tpmfront_resume(struct xenbus_device *dev)
 {
-        struct tpm_private *tp = dev->data;
+       struct tpm_private *tp = dev->data;
        return talk_to_backend(dev, tp);
 }
 
index 59efb7936cb1eee486d367473bc5b4f3a73ef2be..d34882f6199b9ed23a7deb1fe3226c3316e21fa4 100644 (file)
@@ -40,16 +40,18 @@ $(TPM_EMULATOR_TARFILE):
 
 # Create vtpm and TPM emulator dirs
 # apply patches for 1) used as dom0 tpm driver 2) used as vtpm device instance
-$(TPM_EMULATOR_DIR): $(TPM_EMULATOR_TARFILE) 
-       tar -xzf $(TPM_EMULATOR_TARFILE);  
+$(TPM_EMULATOR_DIR): $(TPM_EMULATOR_TARFILE) tpm_emulator.patch tpm_emulator-0.2b-x86_64.patch
+       tar -xzf $(TPM_EMULATOR_TARFILE);
+       rm -rf $(TPM_EMULATOR_DIR)
        mv tpm_emulator-0.2 $(TPM_EMULATOR_DIR); 
        
        -cd $(TPM_EMULATOR_DIR); \
        patch -p1 < ../tpm_emulator-0.2b-x86_64.patch; \
        patch -p1 <../tpm_emulator.patch
 
-$(VTPM_DIR): $(TPM_EMULATOR_TARFILE)
+$(VTPM_DIR): $(TPM_EMULATOR_TARFILE) tpm_emulator-0.2b-x86_64.patch vtpm.patch
        tar -xzf $(TPM_EMULATOR_TARFILE);  
+       rm -rf $(VTPM_DIR)
        mv tpm_emulator-0.2 $(VTPM_DIR); 
 
        -cd $(VTPM_DIR); \
index 7af2f9dd27ceb3e3b23378e564fa92e37da89f49..7be6ffdb809f43ee03ea578bc7861ada1640d2fb 100644 (file)
@@ -37,7 +37,7 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/linux_module.h tpm_emulator/linux_module
 diff -uprN orig/tpm_emulator-0.2-x86_64/Makefile tpm_emulator/Makefile
 --- orig/tpm_emulator-0.2-x86_64/Makefile      2005-09-15 19:21:14.845078568 -0700
 +++ tpm_emulator/Makefile      2005-09-14 20:27:22.000000000 -0700
-@@ -1,16 +1,20 @@
+@@ -1,16 +1,22 @@
  # Software-Based Trusted Platform Module (TPM) Emulator for Linux
  # Copyright (C) 2004 Mario Strasser <mast@gmx.net>
 +# Copyright (C) 2005 INTEL Corp.
@@ -50,7 +50,9 @@ diff -uprN orig/tpm_emulator-0.2-x86_64/Makefile tpm_emulator/Makefile
  # kernel settings
  KERNEL_RELEASE := $(shell uname -r)
 -KERNEL_BUILD   := /lib/modules/$(KERNEL_RELEASE)/build
-+KERNEL_BUILD   := $(XEN_ROOT)/linux-2.6.12-xen0
++CUR_DIR        := $(shell pwd)
++LINUX_VERSION  := $(shell cat $(CUR_DIR)/$(XEN_ROOT)/buildconfigs/mk.linux-2.6-xen | grep "LINUX_VER" | grep "2.6" | gawk '{ print $$3 }' )
++KERNEL_BUILD   := $(XEN_ROOT)/linux-$(LINUX_VERSION)-xen0
  MOD_SUBDIR     := misc
  COMPILE_ARCH    ?= $(shell uname -m | sed -e s/i.86/x86_32/)
  
index 2f8c2ebc679a3b0aed54b6fda42add44b0d2ae6a..845cf011ddfb8446c6e4fb1b2970e433e7b85e55 100644 (file)
@@ -47,7 +47,7 @@
 
 #define STATE_FILE    "/var/vtpm/VTPM"
 #define DMI_NVM_FILE  "/var/vtpm/vtpm_dm_%d.data"
-#define VTPM_BE_DEV   "/dev/vtpm0"
+#define VTPM_BE_DEV   "/dev/vtpm"
 #define VTPM_CTL_DM   0
 
 #ifndef VTPM_MUTLI_VM